package game.players.states;

import com.uqbar.vainilla.DeltaState;

import game.players.SoccerPlayer;
import game.players.cpu.opponent.PassingCPUOppPlayer;
import game.players.cpu.opponent.ShootingCPUOppPlayer;
import game.soccerField.Arc;

public abstract class CPUOppWithBall extends WithBall {

	public CPUOppWithBall(SoccerPlayer player) {
		super(player);
		this.setTeammates(player.getScene().getOpponents());
	}
	
	@Override
	public void update(DeltaState deltaState) {		
		Arc rivalArc = this.getPlayer().getRivalArc();
		if (this.isAtDistanceFromTheArc(rivalArc, 400, 300))
			this.doAShoot();
		if (this.isAtDistanceFromTheArc(rivalArc, 300, 450)) {
			SoccerPlayer player = this.getClosestMate(this.getTeammates());
			this.doAPass(player);
		}
	}
	
	protected void doAShoot() {
		this.getPlayer().setState(new ShootingCPUOppPlayer(this.getPlayer()));
	}
	
	protected void doAPass(SoccerPlayer target) {
		this.getPlayer().setState(new PassingCPUOppPlayer(this.getPlayer(), target));
	}
}
